package com.kevis.zhunblog.elasticSearch.entities;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.sql.Timestamp;
import java.time.LocalDateTime;


/**
 * 博客文章
 * <p>
 * t_article
 */
@Data
@Document(indexName = "zb_article")
public class ArticleEs {
    //此项作为id，不会写到_source里边。

    @Id
    private Integer id;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second_millis)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "uuuu-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    /**
     * 状态
     */
    @Field(type = FieldType.Byte)
    private Byte status;

    /**
     * 文章标题
     */
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String title;

    /**
     * 博客简介
     */
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String summary;

    /**
     * 博客内容
     */
    @Field(type = FieldType.Text)
    private String content;

    /**
     * 博客分类id
     */
    @Field(type = FieldType.Keyword)
    private Integer classId;

    /**
     * 点击数
     */
    @Field(type = FieldType.Integer)
    private Integer numClick;

    /**
     * 点赞数
     */
    @Field(type = FieldType.Integer)
    private Integer numFavorite;

    /**
     * 封面图的id
     */
    @Field(type = FieldType.Integer)
    private Integer thumbnailFileId;

    /**
     * 排序，默认6666
     */
    @Field(type = FieldType.Integer)
    private Integer sort;

    /**
     * 是否开启评论(0:否 1:是)
     */
    @Field(type = FieldType.Byte)
    private Byte openComment;

    /**
     * 作者
     */
    @Field(type = FieldType.Text)
    private String author;

    /**
     * 文章出处
     */
    @Field(type = FieldType.Text)
    private String articlesPart;

    /**
     * 管理员id
     */
    @Field(type = FieldType.Integer)
    private Integer adminId;

    @JsonFormat(shape = JsonFormat.Shape.STRING, locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss.SSS")
    @Field(type = FieldType.Long, format = DateFormat.epoch_millis)
    private Timestamp releaseTime;
}